<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>测试立即购买流程</title>
</head>
<body>
    <h1>测试立即购买流程</h1>
    <p>这个页面模拟立即购买的数据设置和跳转流程</p>
    
    <button onclick="simulateBuyNow()">模拟立即购买（薯片）</button>
    <button onclick="clearData()">清除数据</button>
    <button onclick="goToOrderConfirm()">跳转到订单确认页面</button>
    
    <div id="status"></div>
    
    <script>
        function simulateBuyNow() {
            // 模拟商品详情页的数据格式
            const productData = {
                productId: 7,
                productName: "薯片",
                productPrice: 15,
                productImage: "/images/potatochips.jpg",
                quantity: 1,
                stock: 499
            };
            
            // 模拟ProductDetail.vue中的逻辑
            localStorage.setItem('buyNowProduct', JSON.stringify(productData));
            localStorage.removeItem('checkoutCart');
            
            document.getElementById('status').innerHTML = '<p style="color: green;">立即购买数据已设置：' + JSON.stringify(productData) + '</p>';
            
            // 2秒后自动跳转到订单确认页面
            setTimeout(() => {
                goToOrderConfirm();
            }, 2000);
        }
        
        function clearData() {
            localStorage.removeItem('buyNowProduct');
            localStorage.removeItem('checkoutCart');
            document.getElementById('status').innerHTML = '<p style="color: red;">数据已清除</p>';
        }
        
        function goToOrderConfirm() {
            // 使用修复后的正确路径
            window.location.href = '/order/confirm';
        }
        
        // 页面加载时显示当前localStorage数据
        window.onload = function() {
            const buyNowProduct = localStorage.getItem('buyNowProduct');
            const checkoutCart = localStorage.getItem('checkoutCart');
            
            let status = '<h3>当前localStorage数据：</h3>';
            status += '<p>buyNowProduct: ' + (buyNowProduct || '无') + '</p>';
            status += '<p>checkoutCart: ' + (checkoutCart || '无') + '</p>';
            
            document.getElementById('status').innerHTML = status;
        };
    </script>
</body>
</html>